// src/pages/my/my.vue

<script setup lang="ts">
import { useMemberStore } from "@/stores";
import { onHide } from "@dcloudio/uni-app";

// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync();

// 我的参与的功能块设置
const myParticipation = [
  {
    text: "我的投稿",
    img: "http://192.168.31.72:9000/books-bucket/static/contribute-1.png",
    url: "/pages/mycontribute/mycontribute",
  },
  // {
  //   text: "征稿",
  //   img: "http://192.168.31.72:9000/books-bucket/static/contribute-2.png",
  //   url: "",
  // },
  {
    text: "我的评论",
    img: "http://192.168.31.72:9000/books-bucket/static/contribute-3.png",
    url: "",
  },
  {
    text: "稿件审核",
    img: "http://192.168.31.72:9000/books-bucket/static/contribute-4.png",
    url: "/pages/judge/judge",
  },
  {
    text: "个人信息",
    img: "http://192.168.31.72:9000/books-bucket/static/user-1.png",
    url: "/pages/myinfo/myinfo",
  },
];
// 用户信息的获取
const memberStore = useMemberStore();
console.log(memberStore.profile);

// 组件卸载的时候的提示
onHide(() => {
  console.log("my组件hide");
});
</script>

<template>
  <scroll-view class="viewport" scroll-y enable-back-to-top @scrolltolower="">
    <!-- 个人资料 -->
    <view class="profile" :style="{ paddingTop: safeAreaInsets!.top + 'px' }">
      <!-- 情况1：已登录 -->
      <view class="overview" v-if="memberStore.profile">
        <navigator url="/pagesMember/profile/profile" hover-class="none">
          <image
            class="avatar"
            mode="aspectFill"
            :src="memberStore.profile.avatar"
          ></image>
        </navigator>
        <view class="meta">
          <view class="nickname">
            <!-- TODO 用户名称的显示 -->
            {{ memberStore.profile.name || memberStore.profile.avatar }}
          </view>
          <view class="extra">
            <navigator
              url="/pages/myinfo/myinfo"
              open-type="navigate"
              hover-class="navigator-hover"
            >
              <text class="update">更新头像昵称</text>
            </navigator>
          </view>
        </view>
      </view>
      <!-- 情况2：未登录 -->
      <view class="overview" v-else>
        <navigator url="/pages/login/login" hover-class="none">
          <image
            class="avatar gray"
            mode="aspectFill"
            src="http://localhost:9000/books-bucket/background/unlogin_avatar.png"
          ></image>
        </navigator>
        <view class="meta">
          <navigator
            url="/pages/login/login"
            hover-class="none"
            class="nickname"
          >
            未登录
          </navigator>
          <view class="extra">
            <text class="tips">点击登录账号</text>
          </view>
        </view>
      </view>
      <navigator
        class="settings"
        url="/pagesMember/settings/settings"
        hover-class="none"
      >
        设置
      </navigator>
    </view>
    <!-- 我的投稿 -->
    <view class="orders">
      <view class="title"> 我的投稿 </view>
      <view class="good-nav">
        <view
          v-for="(item, index) in myParticipation"
          :key="index"
          hover-class="none"
        >
          <navigator :url="item.url">
            <image :src="item.img" mode="" />
            <text>{{ item.text }}</text>
          </navigator>
        </view>
      </view>
    </view>
    <!-- 猜你喜欢 -->
  </scroll-view>
</template>

<style lang="scss">
page {
  height: 100%;
  overflow: hidden;
  background-color: #f7f7f8;
}

.viewport {
  background-repeat: no-repeat;
  background-image: url(http://localhost:9000/books-bucket/background/center_bg.png);
  background-size: 100% auto;
}

/* 用户信息 */
.profile {
  margin-top: 20rpx;
  position: relative;

  .overview {
    display: flex;
    height: 120rpx;
    padding: 0 36rpx;
    color: #fff;
  }

  .avatar {
    width: 120rpx;
    height: 120rpx;
    border-radius: 50%;
    background-color: #eee;
  }

  .gray {
    filter: grayscale(100%);
  }

  .meta {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    line-height: 30rpx;
    padding: 16rpx 0;
    margin-left: 20rpx;
  }

  .nickname {
    max-width: 350rpx;
    margin-bottom: 16rpx;
    font-size: 30rpx;

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .extra {
    display: flex;
    font-size: 20rpx;
  }

  .tips {
    font-size: 22rpx;
  }

  .update {
    padding: 3rpx 10rpx 1rpx;
    color: rgba(255, 255, 255, 0.8);
    border: 1rpx solid rgba(255, 255, 255, 0.8);
    margin-right: 10rpx;
    border-radius: 30rpx;
  }

  .settings {
    position: absolute;
    bottom: 0;
    right: 40rpx;
    font-size: 30rpx;
    color: #fff;
  }
}

/* 我的订单 */
.orders {
  position: relative;
  z-index: 99;
  padding: 30rpx;
  margin: 50rpx 20rpx 0;
  background-color: #fff;
  border-radius: 10rpx;
  box-shadow: 0 4rpx 6rpx rgba(240, 240, 240, 0.6);

  .title {
    height: 40rpx;
    line-height: 40rpx;
    font-size: 28rpx;
    color: #1e1e1e;

    .navigator {
      font-size: 24rpx;
      color: #939393;
      float: right;
    }
  }

  // 商品导航区域
  .good-nav {
    width: 100%;
    display: flex;
    justify-content: space-between;
    background-color: #fff;
    padding: 20rpx 16rpx;
    border-radius: 10rpx;

    view {
      navigator {
        display: flex;
        flex-direction: column;
        align-items: center;
      }

      image {
        width: 80rpx;
        height: 80rpx;
      }

      text {
        font-size: 24rpx;
        margin-top: 12rpx;
      }
    }
  }
}

/* 猜你喜欢 */
.guess {
  background-color: #f7f7f8;
  margin-top: 20rpx;
}
</style>
